package logic

import (
	"context"
	"xialou_platform/app/errorx"
	"xialou_platform/services/system/model"

	"xialou_platform/services/system/rpc/internal/svc"
	"xialou_platform/services/system/rpc/systemClient"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysUserUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysUserUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysUserUpdateLogic {
	return &SysUserUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysUserUpdateLogic) SysUserUpdate(in *systemClient.SysUser) (*systemClient.EmptyBody, error) {
	err := l.svcCtx.SysUserModel.Update(l.ctx, &model.SysUser{
		Id:       in.Id,
		DeptId:   in.DeptId,
		Avatar:   in.Avatar,
		Name:     in.Name,
		Password: in.Password,
		Salt:     in.Salt,
		Gender:   in.Gender,
		Email:    in.Email,
		Phone:    in.Phone,
		Status:   in.Status,
		CreateBy: in.CreateBy,
		UpdateBy: in.UpdateBy,
		DelFlag:  in.DelFlag,
		Role:     in.Role,
	})
	if err != nil {
		return nil, errorx.NewReasonError("网络出小差了，请重试刷新再试。", err.Error())
	}
	return &systemClient.EmptyBody{}, nil
}
